package di

import (
	"go.uber.org/dig"
	"sync"
)

var (
	defaultInject *Inject

	syncOnce = &sync.Once{}
)

func InjectInstance() *Inject {
	if defaultInject == nil {
		syncOnce.Do(func() {
			defaultInject = NewInject()
		})
	}

	return defaultInject
}

type Inject struct {
	*dig.Container
}

func NewInject() *Inject {
	c := dig.New()
	container := &Inject{c}
	//注入repo
	container.InjectRepo()

	//注入service
	container.InjectService()

	//注入controller
	container.InjectController()
	return container
}
